home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / Samples / Moofwars 1.02 / MoofWars Sprocket / •Source / TShotSprite.cp < prev    next >
Encoding:
Text File  |  1997-11-09  |  2.6 KB  |  113 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. #
  3. TShotSprite.cp
  4.  
  5. This class represents any shots in the game, friendly or enemy.
  6.  
  7.  
  8. Author: Timothy Carroll
  9. Apple Developer Technical Support
  10. timc@apple.com
  11.  
  12. Modification History: 
  13.  
  14. 1/23/97     TMC        Added include for Moofwars.h so that MrC will compile
  15. 8/15/96        TMC     Initial Release
  16.  
  17. Copyright © 1996, 1997 Apple Computer, Inc., All Rights Reserved
  18.  
  19. You may incorporate this sample code into your applications without
  20. restriction, though the sample code has been provided "AS IS" and the
  21. responsibility for its operation is 100% yours.  However, what you are
  22. not permitted to do is to redistribute the source as "DSC Sample Code"
  23. after having made changes. If you're going to re-distribute the source,
  24. we require that you make it clear in the source that the code was
  25. descended from Apple Sample Code, but that you've made changes.
  26.  
  27. *************************************************************************************/
  28.  
  29. #include "Moofwars.h"
  30. #include "TShotSprite.h"
  31.  
  32.  
  33. TShotSprite::TShotSprite (TShotSpriteData *data):
  34. TSprite((TSpriteData *) data)
  35. {
  36.     fDuration = data->duration;
  37.     gShotsOnBoard +=1;
  38. }
  39.  
  40.  
  41. TShotSprite::~TShotSprite (void)
  42. {
  43.     gShotsOnBoard -=1;
  44. }
  45.     
  46. void
  47. TShotSprite::ProcessSprite (void)
  48. {
  49. // Because of changes in the current implementation, the following code won't compile.
  50. // It implements a primitive seeking algorithm.
  51. //
  52. // We basically look 3 frames ahead and try to move our sprite so that we'll hit the ship.
  53.     
  54. #if 0
  55.     long deltaX, deltaY;
  56.     deltaX = (gEnemyShipToSeek->fCurrentX+3*gEnemyShipToSeek->fCurVelocityX+(12<<16)
  57.                  - this->fCurrentX-3*this->fCurVelocityX);
  58.     deltaY = (gEnemyShipToSeek->fCurrentY+3*gEnemyShipToSeek->fCurVelocityY+(12<<16)
  59.                  - this->fCurrentY-3*this->fCurVelocityY);
  60.     
  61.     if (deltaX < 0)
  62.     {
  63.         fCurVelocityX -= (2 << 15);
  64.     }
  65.     else if (deltaX > 0)
  66.     {
  67.         fCurVelocityX += (2 << 15);
  68.     }
  69.     
  70.     if (deltaY < 0)
  71.     {
  72.         fCurVelocityY -= (2 << 15);
  73.     }
  74.     else if (deltaY > 0)
  75.     {
  76.         fCurVelocityY += (2 << 15);
  77.     }
  78.     
  79. #endif
  80.  
  81.     // If the sprite is invisible, we should delete it, otherwise we should make it invisible
  82.     // if its duration is up.
  83. #if qShotsHaveRange
  84.     if (fVisibility == kInvisible)
  85.     {
  86.         delete this;
  87.     }
  88.     else
  89.     {
  90.         fDuration -= 1;
  91.         if (fDuration == 0)
  92.             SetVisibility(kInvisible);
  93.     }
  94. #endif
  95.  
  96.     TSprite::ProcessSprite();
  97.     TSprite::Bounce (&gWorldBounds);
  98. }
  99.  
  100. void
  101. TShotSprite::Collision (TSprite *theSprite)
  102. {
  103. #pragma unused (theSprite)
  104.  
  105.     // Change our sprite to the "hit" shape.
  106.     fFace = 2;
  107.     
  108.     if (fDuration > 3)
  109.         fDuration = 3;
  110.     // This will delete the sprite.
  111.     //SetVisibility(kInvisible);
  112.  
  113. }